package com.ruoyi.project.oms.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.db.oms.domain.OmsOrder;
import com.ruoyi.db.oms.domain.query.OmsOrderQueryVo;
import com.ruoyi.project.oms.service.OmsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单列表Controller
 *
 * @author yfy
 * @date 2020-04-27
 */
@Api(tags = "oms管理：订单列表管理")
@RestController
@RequestMapping("/oms/order")
public class OmsOrderController extends BaseController
{
    @Autowired
    private OmsOrderService omsOrderService;

    @ApiOperation("订单超时处理")
    public AjaxResult updateAuto()
    {
        System.out.println("执行订单超时处理");
        OmsOrder omsOrder = new OmsOrder();
        return AjaxResult.success(omsOrderService.omsOrderUpdateAuto(omsOrder));
    }

    @ApiOperation("查询订单列表列表")
    @PreAuthorize("@ss.hasPermi('oms:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsOrderQueryVo omsOrderQueryVo)
    {
        startPage();
        List<OmsOrder> list = omsOrderService.selectOmsOrderList(omsOrderQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出订单列表列表")
    @Log(title = "订单列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('oms:order:export')")
    @GetMapping("/export")
    public AjaxResult export(OmsOrderQueryVo omsOrderQueryVo)
    {
        List<OmsOrder> list = omsOrderService.selectOmsOrderList(omsOrderQueryVo);
        ExcelUtil<OmsOrder> util = new ExcelUtil<OmsOrder>(OmsOrder.class);
        return util.exportExcel(list, "order");
    }

    @ApiOperation("获取订单列表详细信息")
    @Log(title = "订单列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oms:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(omsOrderService.selectOmsOrderById(id));
    }

    @ApiOperation("新增订单列表")
    @Log(title = "订单列表", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('oms:order:add')")
    @PostMapping
    public AjaxResult add(@RequestBody OmsOrder omsOrder)
    {
        return toAjax(omsOrderService.insertOmsOrder(omsOrder));
    }

    @ApiOperation("修改订单列表")
    @Log(title = "订单列表", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('oms:order:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody OmsOrder omsOrder)
    {
        return toAjax(omsOrderService.updateOmsOrder(omsOrder));
    }

    @ApiOperation("删除订单列表")
    @Log(title = "订单列表", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('oms:order:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsOrderService.deleteOmsOrderByIds(ids));
    }
}
